package jpg1.jpg1zad2;

import java.util.EmptyStackException;

/**
 * Autor: Daniel Michalski
 * Data: 05.07.13
 */

public class Main {
    public static void main(String[] args) {
        Stos stos = new Stos(3);

        stos.push("1");
        stos.push("2");
        stos.push("3");

        System.out.println(stos.isEmpty());

        stos.pop();
        stos.pop();
        stos.pop();

        System.out.println(stos.isEmpty());
    }
}


interface Stack {
    public Object pop() throws EmptyStackException;

    public void push(Object item);

    public boolean isEmpty();
}

class Stos extends EmptyStackException implements Stack {

    private Object[] stos;
    private int wskaznik;

    Stos() {
        stos = new Object[10];
        wskaznik = -1;
    }

    Stos(int stackSize) {
        stos = new Object[stackSize];
        wskaznik = -1;
    }

    public Object pop() throws EmptyStackException {
        if (wskaznik == -1) {
            throw new EmptyStackException();
        } else {
            int w = wskaznik;
            wskaznik--;
            return stos[w];
        }
    }

    public void push(Object item) {
        if (wskaznik < 9) stos[++wskaznik] = item;
    }

    public boolean isEmpty() {
        return wskaznik == -1;
    }
}


